package cn.edu.zjicm.wordsnet_d.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.edu.zjicm.wordsnet_d.R;
import cn.edu.zjicm.wordsnet_d.activity.base.BaseSlideActivity;
import cn.edu.zjicm.wordsnet_d.util.NightModeUtil;
import cn.edu.zjicm.wordsnet_d.util.Utils;
import cn.edu.zjicm.wordsnet_d.view.BadgeView;

public class MenuAdapter extends BaseAdapter {
	private int paddingTopBottom, paddingTopBottomForBottom;
	private String[] title = { "我的词汇本", "更改学习计划", "打卡日历", "校园排行榜", "设置", "知米听力", "夜间模式", "给个好评", "推荐给好友" };
	private int[] icons = { R.drawable.book_ic, R.drawable.ico_change_plan, R.drawable.calendar, R.drawable.leaderboard, R.drawable.settings_ic, R.drawable.listen_introduction_icon,
			R.drawable.night_mode_ic, R.drawable.comment_ic, R.drawable.recommend_to_friends };
	BaseSlideActivity mBaseActivity;

	public boolean addRedPoint;

	public MenuAdapter(BaseSlideActivity mBaseActivity) {
		this.mBaseActivity = mBaseActivity;
		paddingTopBottom = Utils.changeDipToPx(mBaseActivity, 11);
		paddingTopBottomForBottom = Utils.changeDipToPx(mBaseActivity, 4);
	}

	@Override
	public int getCount() {
		return title.length;
	}

	@Override
	public Object getItem(int position) {
		return title[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = LayoutInflater.from(mBaseActivity).inflate(R.layout.view_menu_item, null);
		ImageView menu_icon = (ImageView) view.findViewById(R.id.menu_item_icon);
		TextView menu_tv = (TextView) view.findViewById(R.id.menu_item_tv);
		TextView menu_tv2 = (TextView) view.findViewById(R.id.menu_item_tv2);
		TextView divider = (TextView) view.findViewById(R.id.menu_divider_tv);

		menu_icon.setImageResource(icons[position]);
		menu_tv.setText(title[position]);

		if (position == 4 && addRedPoint) {
			BadgeView badgeView = new BadgeView(mBaseActivity, menu_tv);
			badgeView.setTextSize(7);
			badgeView.show();
		}

		if (position == 6) {
			if (NightModeUtil.getDayNightMode(mBaseActivity) == NightModeUtil.THEME_SUN) {
				menu_tv.setText("夜间模式");
				menu_icon.setImageResource(R.drawable.night_mode_ic);
			} else {
				menu_tv.setText("日间模式");
				menu_icon.setImageResource(R.drawable.night_mode_ic_day);
			}
		}

		if (position == 5) {
			divider.setVisibility(View.VISIBLE);
		}

		if (position == 6) {
			divider.setVisibility(View.VISIBLE);
			menu_tv.setTextSize(14);
			menu_tv.setTextColor(Color.parseColor("#99ffffff"));
			RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.base_layout);
			rl.setPadding(paddingTopBottom, paddingTopBottomForBottom, 0, paddingTopBottomForBottom);
		} else if (position > 6 && position <= 8) {
			menu_tv.setTextColor(Color.parseColor("#99ffffff"));
			menu_tv.setTextSize(14);
			RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.base_layout);
			rl.setPadding(paddingTopBottom, paddingTopBottomForBottom, 0, paddingTopBottomForBottom);
			// menu_tv.setTextColor(Color.argb(204, 255, 255, 255));
		}
		return view;
	}
}
